package org.wu.framework.core.utils;


import java.io.IOException;
import java.io.InputStream;

public class StreamUtils {


    private static final byte[] EMPTY_CONTENT = new byte[0];

    /**
     * Copy the contents of the given InputStream into a new byte array.
     * <p>Leaves the stream open when done.
     * @param in the stream to copy from (may be {@code null} or empty)
     * @return the new byte array that has been copied to (possibly empty)
     * @throws IOException in case of I/O errors
     */
    public static byte[] copyToByteArray( InputStream in) throws IOException {
        if (in == null) {
            return EMPTY_CONTENT;
        }

        return in.readAllBytes();
    }

}
